/**
 * 
 */
package com.ideazd.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ideazd.api.model.Propaganda;
import com.ideazd.api.service.PropagandaService;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Logger;

/**
 * @author yzz
 * @create 2016年3月21日 下午2:00:29
 */
@ControllerBind(controllerKey="propaganda")
public class PropagandaController extends Controller {
	private static final Logger log = Logger.getLogger(PropagandaController.class);
	private PropagandaService propagandaService = new PropagandaService();
	
	/**
	 * 宣传图片展示
	 */
	public void getPropagandaImg(){
		String picPosition = getPara("picPosition");
		Map<Object, Object> ret = new HashMap<Object,Object>();
		
		if(StrKit.isBlank(picPosition)){
			ret.put("code","-2");
			ret.put("msg","必传参数不允许为空");
			renderJson(ret);
			return;
		}
		
		try {
			
			List <Propaganda> propagandaList = propagandaService.getPropagandaList(picPosition);
			List<Map<Object, Object>> dataList = new ArrayList<Map<Object, Object>>();
			
			for(Propaganda propaganda : propagandaList){
				Map<Object, Object> dataMap = new HashMap<Object,Object>();
				dataMap.put("picAddress", PropKit.get("server_uri") + propaganda.get("picaddress"));
				dataMap.put("operationEvent", propaganda.get("operationevent").toString());
				dataMap.put("eventInfo", propaganda.get("eventinfo"));
				dataList.add(dataMap);
			}
			
			ret.put("code","0");
			ret.put("msg","成功");
			ret.put("data", dataList);
			
		} catch (Exception e) {
			ret.put("code","-1");
			ret.put("msg",e.getMessage());
		}
		
		renderJson(ret);
		return;
		
	}

}
